package ListNodePractice;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class PalindromeList_I {
    public static boolean isPalindrome(ListNode head) {
        if (head == null) {
            return true;
        }
        ListNode temp = head;
        Stack<Integer> stack = new Stack<>();
        while(temp!=null){
            stack.add(temp.val);
            temp = temp.next;
        }
        while(head!=null){
            if(stack.pop()!=head.val){
                return false;
            }
            head=head.next;
        }
        return true;
    }

    public static void main(String[] args) {

        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);
        ListNode listNode3 = new ListNode(2);
        ListNode listNode4 = new ListNode(1);

        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;

        System.out.println(isPalindrome(listNode1));
    }
}
